﻿using MediatR;
using S.Eartag.API.Application.Command.LamBingCommand;
using S.Eartag.Infrastructure.Interface;

namespace S.Eartag.API.Application.CommandHandlers.LamBingCommandHandler
{
    public class LamBingAllDelCommandHandler : IRequestHandler<LamBingAllDelCommand, int>
    {
        private readonly ILamBingRepository lamBingRepository;

        public LamBingAllDelCommandHandler(ILamBingRepository lamBingRepository)
        {
            this.lamBingRepository = lamBingRepository;
        }

        public async Task<int> Handle(LamBingAllDelCommand request, CancellationToken cancellationToken)
        {
            var Id = request.ids.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
            var list = await lamBingRepository.GetValues(x => Id.Contains(x.Id));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await lamBingRepository.UpdateAll(list);
        }
    }
}
